package org.agile2soft.nexoma.tapestry.services.security;

import java.util.List;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.userdetails.UserDetails;

@SuppressWarnings("serial")
public class MyUserDetailsImpl implements UserDetails {

    private List<GrantedAuthority> _authorities = CollectionFactory.newList();

    private String _password;
    private String _username;

    public MyUserDetailsImpl( String username ) {
        _username = username;
    }

    public GrantedAuthority[] getAuthorities() {

        GrantedAuthority[] authorities = new GrantedAuthority[_authorities.size()];
        int i = 0;
        for ( GrantedAuthority authority: _authorities ) {
            authorities[i++] = authority;
        }
        return authorities;
    }

    public void addAuthority( GrantedAuthority authority ) {

        _authorities.add( authority );
    }

    public String getPassword() {

        return _password;
    }

    public void setPassword( String password ) {

        _password = password;
    }

    public String getUsername() {

        return _username;
    }

    public void setUsername( String username ) {

        _username = username;
    }

    public boolean isAccountNonExpired() {

        return true;
    }

    public boolean isAccountNonLocked() {

        return true;
    }

    public boolean isCredentialsNonExpired() {

        return true;
    }

    public boolean isEnabled() {

        return true;
    }
}

